﻿
var SushiSprite = cc.Sprite.extend({
    touchListener: null,
    index: null,
    
    onEnter: function () {
       
        this._super();
        this.addTouchEventListenser();
    },
    onExit: function () {
      
    },
    addTouchEventListenser: function () {

        this.touchListener = cc.EventListener.create({
            event: cc.EventListener.TOUCH_ONE_BY_ONE,
           swallowTouches: true,
            onTouchBegan: function (touch, event) {
                var pos = touch.getLocation();
                var target = event.getCurrentTarget();
                if (cc.rectContainsPoint(target.getBoundingBox(), pos)) {
                    cc.log("touched");
                    cc.log("target.getParent():" + target.getParent());

                    target.getParent().updateScore();
                    target.removeTouchEventListenser();                   
                    target.removeFromParent();

                  
                   
                    
                    return true;
                }
                return false;
            }
        });

        cc.eventManager.addListener(this.touchListener, this);
    },
    removeTouchEventListenser: function () {
        cc.eventManager.removeListener(this.touchListener);
    }
});